-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 1D advection-diffusion #55
Add 1D advection-diffusion #55
Conversation
Have added the functions to do this but the way the multiple dispatch is used is not so good. Need to write some tests to make sure that everything is working correctly then check with Navid if there is a better to way to set this up. I think doing it this way generalises very easy to the 3D domain.
Add the example to the documents as well.
Tests for one dimensional advection-diffusion are failing on GPUs. I have used similar code to the two dimensional tests which pass so not sure exactly why. Looks to be the same problem for all four tests, a method issue with MethodError: no method matching mul!(::CuArray{ComplexF64, 1, CUDA.Mem.DeviceBuffer}, ::CUDA.CUFFT.rCuFFTPlan{Float64, -1, false, 1}, ::Vector{Float64}, ::Bool, ::Bool) |
Not sure if this is the problem but worth trying to see if the issue is `c0` not being of type `CuArray` in the GPU run.
@navidcy I am still quite unfamiliar with the |
One way I thought function Problem(dev, advecting_flow::Function; kwargs...)
# Set up one dimensional advection-diffusion `Problem`
end
function Problem(dev, advecting_flow::Vector{Function}; kwargs...)
if length(advecting_flow) == 2
# Set up two dimensional advection-diffusion `Problem`
elseif length(advecting_flow) == 3
# Set up three dimensional advection-diffusion `Problem`
else
# throw error
end
end So we find the dimension of the problem from the There is probably a neater/simpler way but this was what I came up with.. |
Hopefully this fixes the test that fail on the `GPU`.
I'll have a look at the PR soon! |
No rush! |
Tests all pass now by using function gridpoints(grid::OneDGrid{T, A}) where {T, A}
X = [ grid.x[i] for i=1:grid.nx ]
return A(X)
end to |
This is a breaking change. Not sure if it is the best way to setup the methods but it is an idea and better than what I had initially.
I have changed the way the methods are called for function Problem(dev, advecting_flow::Function;
nx = 128,
Lx = 2π,
κ = 0.1,
dt = 0.01,
stepper = "RK4",
steadyflow = false,
T = Float64
)
# Setup OneDProblem
end For the two dimensional function Problem(dev, advecting_flow::NamedTuple=(u=noflow, v=noflow);
nx = 128,
Lx = 2π,
ny = nx,
Ly = Lx,
κ = 0.1,
η = κ,
dt = 0.01,
stepper = "RK4",
steadyflow = false,
T = Float64
)
# Set up TwoDProblem
end It could be extended to include a function Problem(dev, advecting_flow::NamedTuple; parameters)
if length(advecting_flow)== 2
#Setup two dimensional `Problem`
elseif length(advecting_flow ) == 3
#Setup three dimensional `Problem`
else
#Throw error
end
end Not sure what is best or if you want to implement this breaking change! |
Here is one way we could structure things with an "Abstract supertype for an advecting flow"
abstract type AdvectingFlow end The the struct OneDAdvectingFlow <: AdvectingFlow
"Function for the x-component of the advecting flow"
u :: Function
"Whether of not the flow is time dependent"
steadyflow :: Bool
end with a constructor that is exported and has default values like is currently set in OneDAdvectingFlow(; u = noflow, steadyflow = false) = OneDAdvectingFlow(u, steadyflow) Then when setting up a # set up params
# use default values
advecting_flow = OneDAdvectingFlow()
prob = TracerAdvectionDiffusion.Problem(dev, advecting_flow; params) or choose some other function for the flow # set up params
# set a time dependent flow
u(x, t) = #some function
advecting_flow = OneDAdvectingFlow(; u = u, steadyflow = false)
prob = TracerAdvectionDiffusion.Problem(dev, advecting_flow; params) Inside the module this would just mean changing This could generalise to the 2D and 3D cases quite easily and might be less of a rewrite of the code than using a |
By creating the `abstract type AdvectingFlow` we can use types `OneDAdvectingFlow` and `TwoDAdvectingFlow` for the methods in `Problem`.
I have updated the |
sorry for slacking on this... |
I liked the |
No worries! |
…s/PassiveTracerFlows.jl into add-1Dadvection-diffusion
…eTracerFlows.jl into add-1Dadvection-diffusion
Nice work! Thanks! |
Fix typo Co-authored-by: Navid C. Constantinou <[email protected]>
…eTracerFlows.jl into add-1Dadvection-diffusion
feel free to merge when tests pass |
and tag a new release, you can do that by going to the merge commit and just commenting |
Comments on pull requests will not trigger Registrator, as it is disabled. Please try commenting on a commit or issue. |
haha, just me saying that got the tagbot triggered :) |
Will do! Will look into adding an option for using a |
This PR adds ability to advect-diffuse in one dimension. I changed
ConstDiffParams
->ConstDiffTimeVaryingFlowParams
. This means that the various parameter structs all now have type that isConstDiff...Params
where...
is the flow specified by the user.The one dimensional
Problem
is not done in the most elegant way. To use multiple dispatch I added the argumentonedim::Bool
toProblem
. If eithertrue
orfalse
(not ideal) is passed toProblem
afterdev
it will setup a 1DProblem
. Not great I know but I could not think of a better way to do it (without making a new functionProblem1D
). There is an idea I had of how this could be done in a comment further down now.. Any suggestions would be great!The
Problem
setup is all the same except now there areConstDiffSteadyFlowParams
,ConstDiffTimeVaryingFlowParams
, andVars
in both one and two dimensions. ForEquation
multiple dispatch based on theparams
is used and forcalcN!
,calcN!_steadyflow
I used multiple dispatch based on grid type. TheVars
constructor uses the grid type but when I changedAbstractGrid{T}
->OneDGrid
(or TwoDGrid) I could not use
OneDGrid{T}so added the parameter
T`.Using a
TimeVarying
background flow (I usedu(x) = (x, log(1 + t/2500))
) the advection-diffsuion of a Gaussian initial condition is1D_advection-diffusion.mp4